<template>
  <div class="data-list">
    <div class="searchinput" style="padding:0 0 10px 0">
      <el-input v-model="filter" @input="searchData" :placeholder="filterParams.tips" suffix-icon="fa fa-search"/>
    </div>
    <d2-crud
      ref="d2Crud"
      :data="resultList"
      :columns="columns"
      :options="options"
      :loading="loading"
      index-row
      selection-row
      @selection-change="selectChange"
      @pagination-current-change="pageChange"
      @current-change="handleCurrentChange"
    >
    </d2-crud>
  </div>

</template>
<script>
  import deptApi from "@/api/system/dept";
  import roleApi from "@/api/system/role";
  import caseApi from "@/api/system/case";
  import utils from '@/assets/utils/zhzf-util';

  export default {
    name: "data-table",
    data() {
      return {
        loading: false,
        dialogVisible: false,
        dataList: [],
        resultList: [],
        form: {},
        columns: [],
        selected: [{id:'8192acbfe12440d791ebe7510364f1dc'},{id:'96ae6b92f9744e90be5bdef5f42a575f'}],
        pagination: {
          currentPage: 1,
          pageSize: 1000,
          total: 0,
        },
        options: {
          stripe: true,
          highlightCurrentRow: true
        },
        value: '',
        filterParams: {tips: '', keys: []},
        filter: '',
        currentrow: '',
        isSignal:false,
        formtype:''
      };
    },
    mounted() {
    },
    methods: {
      async initPage(method, param, cols,isNoPage,formtype,isSignal) {
        this.loading = true;
        this.columns = cols;
        let casecauseId;
        this.formtype = formtype;
        let res = await method({...param, ...(isNoPage?{}:this.pagination)});
        this.dataList = res.data.rows;
        this.resultList = this.dataList;
        this.pagination.total = res.data.total;
        this.isSignal=isSignal;
        this.dataresize(cols);
        this.loading = false;
      },
      selectChange(selection) {
        if(this.isSignal){
          this.$refs.d2Crud.$children[0].clearSelection();
          let curr = selection.length>1?null:selection[0];
          this.$refs.d2Crud.$children[0].setCurrentRow(curr);
        }else{
          this.selected = selection;
        }
      },
      dataresize(cols) {
        let tmp = [];
        let tmp2 = [];
        cols.forEach(item => {
          tmp2.push(item.key);
          tmp.push(item.title);
        });
        this.filterParams = {tips: tmp.join(' / '), keys: tmp2};
      },
      searchData() {
        this.resultList = this.dataList.filter(item => {
          let keys = this.filterParams.keys;
          let flag = keys.some(k => item[k].indexOf(this.filter) != -1);
          return flag;
        });
      },
      pageChange(currentPage) {
        this.pagination.currentPage = currentPage;
      },
      handleCurrentChange(currentRow, oldCurrentRow) {
        this.currentrow = currentRow
      }
    }
  };
</script>
<style scoped lang="scss">
  .el-dialog__body {
    padding-top: 0 !important;

    .data-list {
      padding: 0;

      .el-select--default {
        width: 60% !important;
      }

      .d2-crud {
        max-height: 55vh;
        overflow: auto;
      }
    }

  }
</style>
